﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _004基础类练习
{
    class Student
    {
        public string Name { get; set; }//姓名
        private char _sex;//性别
        public char Sex
        {
            get { return _sex; }
            set { 
                if(value == '男' || value == '女')
                    _sex = value; 
            }
        }
        private int _age;//年龄

        public int Age
        {
            get { return _age; }
            set {
                if(value > 0 && value < 25)
                     _age = value; 
            }
        }

        public int LanguageScore { get; set; }//语文成绩
        public int MathematicsScore { get; set; }//数学成绩
        public int EnglishScore { get; set; }//英语成绩

        public Student() { }
        public Student(string name,char sex,int age,int l,int m,int e)
        {
            Name = name;
            Sex = sex;
            Age = age;
            LanguageScore = l;
            MathematicsScore = m;
            EnglishScore = e;
        }

        public void SayHello()
        {
            Console.WriteLine("你好,我叫{0},今年{1},总成绩:{2},平均成绩{3}"
                                ,Name,Age,TotalScore(),AverageScore()
                );
        }

        //计算总分
        private int TotalScore()
        {
            return LanguageScore + MathematicsScore + EnglishScore;
        }
        //计算平均分
        private float AverageScore()
        {
            return TotalScore() / 3.0f;
        }



    }
}
